import cv2
image=cv2.imread('hat.png',cv2.IMREAD_GRAYSCALE)
cv2.imshow("Input",image)
kernel1=cv2.getStructuringElement(cv2.MORPH_RECT,(5,5))
image1=cv2.morphologyEx(image,cv2.MORPH_ERODE,kernel1)
image2=cv2.morphologyEx(image,cv2.MORPH_DILATE,kernel1)
image3=cv2.morphologyEx(image,cv2.MORPH_OPEN,kernel1)
image4=cv2.morphologyEx(image,cv2.MORPH_CLOSE,kernel1)
image5=cv2.morphologyEx(image,cv2.MORPH_GRADIENT,kernel1)
image6=cv2.morphologyEx(image,cv2.MORPH_TOPHAT,kernel1)
image7=cv2.morphologyEx(image,cv2.MORPH_BLACKHAT,kernel1)
cv2.imshow('image1',image1)
cv2.imshow('image2',image2)
cv2.imshow('image3',image3)
cv2.imshow('image4',image4)
cv2.imshow('image5',image5)
cv2.imshow('image6',image6)
cv2.imshow('image7',image7)
cv2.waitKey()
cv2.destroyWindow()